package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.WxReplyItemDao;
import com.mstore.pojo.Reply;
import com.mstore.pojo.WxReplyItem;

public class WxReplyItemService {
	private WxReplyItemDao wxReplyItemDao;

	public WxReplyItemDao getWxReplyItemDao() {
		return wxReplyItemDao;
	}

	public void setWxReplyItemDao(WxReplyItemDao wxReplyItemDao) {
		this.wxReplyItemDao = wxReplyItemDao;
	}

	/**
	 * 
	 * 保存多图文
	 */
	public void saveWxReplyItem(WxReplyItem wxReplyItem) {
		wxReplyItemDao.save(wxReplyItem);
	}

	/**
	 * 
	 * 查询多图文
	 */
	public List<Reply> watchReplyItem(Reply reply) {
		List<Reply> replies = new ArrayList<Reply>();
		List<Object> objects = wxReplyItemDao.watchReplyItem(reply);
		for (Object object : objects) {
			Reply re = (Reply) object;
			re.setCreateTime(re.getCreateTime().substring(0,
					re.getCreateTime().indexOf(".")));
			if (re.getTitle() != null && re.getTitle().length() > 15) {
				re.setTitle(re.getTitle().substring(0, 15) + "...");
			}
			replies.add(re);
		}
		return replies;
	}

	/**
	 * 
	 * 删除多图文
	 */
	public void delReplyItem(Reply reply) {
		wxReplyItemDao.delReplyItem(reply);
	}

	/**
	 * 
	 * 通过reply的id查询WxReplyItem
	 */
	public List<WxReplyItem> selectByReplyId(Reply reply) {
		List<WxReplyItem> item = new ArrayList<WxReplyItem>();
		List<Object> objects = wxReplyItemDao.selectReplyId(reply);
		for (Object object : objects) {
			WxReplyItem wxitem = (WxReplyItem) object;
			item.add(wxitem);
		}
		return item;
	}

	/**
	 * 
	 *  修改多图文
	 */
	public void update(WxReplyItem wReplyItem) {
		wxReplyItemDao.update(wReplyItem);
	}

	/**
	 * 更新
	 */
	public void updateWxReplyItem(WxReplyItem wxReplyItem) {
		wxReplyItemDao.updateWxReplyItem(wxReplyItem);
	}

	/**
	 * 
	 * 删除单个图文
	 */
	public void deleteReplyItem(WxReplyItem wxRepkyItem) {
		wxReplyItemDao.deleteReplyItem(wxRepkyItem);
	}
}
